package com.altocloud.application;

import java.io.File;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.ParseException;

//import com.altoCloud.parsingUtility.ParseDataFilesLevel1;
//import com.altoCloud.testUtility.FileIterate;
import com.altocloud.database.DbUtil;
import com.altocloud.parse.Level3;

public class ApplicationLevel3 {

	File path;

	void iterateAllMesowestCSVFiles(String filePath)
	{
		File path =new File(filePath);
		setPath(path);	
		int i=0;
		 File [] files = path.listFiles();
		    while(i < files.length){
		    	System.out.println("inside for loop");
		        if (files[i].isFile()){ //this line weeds out other directories/folders
		            System.out.println("************"+files[i].toString()+"**********");
		          Level3 p= new Level3();
		          p.parseCsvFile(files[i].toString());
		        } 
		        i++;
		    }
	} 
	
	void iterateMesowestCSVFiles(int size, String filePath)
	{
	File path =new File(filePath);
	setPath(path);	
	int i=0;
	 File [] files = path.listFiles();
	  
	 while(i < files.length && i<size){
	    	System.out.println("inside for loop");
	        if (files[i].isFile()){ //this line weeds out other directories/folders
	            System.out.println("************"+files[i].toString()+"**********");
	          Level3 p= new Level3();
	          p.parseCsvFile(files[i].toString());
	        } 
	        i++;
	    }
	
	} 
	
	void iterateAllWeatherFiles(String filePath)
	{
		File path =new File(filePath);
		setPath(path);	
		int i=0;
		 File [] files = path.listFiles();
		    while(i < files.length){
		    	System.out.println("inside for loop");
		        if (files[i].isFile()){ //this line weeds out other directories/folders
		            System.out.println("************"+files[i].toString()+"**********");
		          Level3 p= new Level3();
		          try {
					p.parseOutFile(files[i].toString());
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		        } 
		        i++;
		        System.out.println("NextFile");
		    }
	} 
	
	void iterateWeatherFiles(int size, String filePath)
	{
		File path =new File(filePath);
		setPath(path);	
		int i=0;
		 File [] files = path.listFiles();
		    while(i < files.length && i<size){
		    	System.out.println("inside for loop");
		        if (files[i].isFile()){ //this line weeds out other directories/folders
		            System.out.println("************"+files[i].toString()+"**********");
		          Level3 p= new Level3();
		          try {
					p.parseOutFile(files[i].toString());
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		        } 
		        i++;
		    }
	} 
	
	public File getPath() {
		return path;
	}

	public void setPath(File path) {
		this.path = path;
	}

	public static void main(String[] args){
		ApplicationLevel1 fi = new ApplicationLevel1();
		//To iterate over specified number of mesowest_csv.tbl files
		System.out.println("Execution Start");
		Long startTime = System.currentTimeMillis();  
		
		//fi.iterateMesowestCSVFiles(1,"E:\\Study Related\\3rd sem\\CMPE 226\\Proj 1\\cmpe 226 data\\CSV\\csv");
		 
		//To iterate over ALL  mesowest_csv.tbl files
		//fi.iterateAllMesowestCSVFiles("C:/jars/226Data/csv");
		
		//To iterate over specified number of mesowest.out file
		fi.iterateWeatherFiles(95,"E:\\Study Related\\3rd sem\\CMPE 226\\Proj 1\\cmpe 226 data\\OUT\\out");
		
		Long endTime = System.currentTimeMillis();
		Long timeTaken = endTime - startTime;
		System.out.println("Execution End");
		System.out.println("Time Taken is : " + timeTaken + " ms");
		 
		//To iterate over ALL mesowest.out file
		//fi.iterateAllWeatherFiles("C:/jars/226Data/out");
	}
}
